package server;

import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.UnknownHostException;
import java.nio.charset.Charset;
import java.util.HashMap;

import org.apache.mina.core.service.IoAcceptor;
import org.apache.mina.core.session.IoSession;
import org.apache.mina.filter.codec.ProtocolCodecFilter;
import org.apache.mina.filter.codec.textline.TextLineCodecFactory;
import org.apache.mina.filter.logging.LoggingFilter;
import org.apache.mina.transport.socket.nio.NioSocketAcceptor;

import data.Room;



public class Server
{
	public static HashMap<Long, IoSession> sessions = new HashMap<Long, IoSession>();
	public static HashMap<String , Room> rooms = new HashMap<String, Room>();
	
	private final int PORT = 2002;
	public Server()
	{
		IoAcceptor acceptor = new NioSocketAcceptor();

        acceptor.getFilterChain().addLast( "logger", new LoggingFilter() );
        acceptor.getFilterChain().addLast( "codec", new ProtocolCodecFilter( new TextLineCodecFactory( Charset.forName( "UTF-8" ))));
        acceptor.setHandler(new CocaroHandler());
        try
		{
			acceptor.bind(new InetSocketAddress("localhost", this.PORT));
			System.out.println("server waiting....");
		}
        catch(Exception e)
        {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
        
	}
}
